<html>
<head>
<title>用户管理</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<link rel="shortcut icon" href="resources/images/lock.png" type="image/x-icon">
<link rel="stylesheet" href="resources/css/stylemain.css">
<link rel="stylesheet" href="resources/layui/css/layui.css">

<link rel="stylesheet" href="resources/layui/css/treeTable.css">
<link rel="stylesheet" href="resources/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
<script src="resources/layui/layui.all.js"></script>
<script type="text/javascript" src="resources/js/jquery.js"></script>
<script type="text/javascript" src="resources/js/base64.js"></script>

</head>
<body>
<div style="width:300px;display:none" id="tb_rolelist">
	<table class="layui-hide" id="rolelist" lay-filter="rolelist"></table>
</div>
<div class="layui-form">
  <table class="layui-hide" id="tbl_user" lay-filter="tbl_user"></table>
  <div id="page"></div>
  <script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon layui-icon-add-circle"></i> 添加</button>
    <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="del"><i class="layui-icon layui-icon-delete"></i> 删除</button>
    <button class="layui-btn layui-btn-sm" lay-event="edit"><i class="layui-icon layui-icon-edit"></i> 修改</button>
    <button class="layui-btn layui-btn-sm" lay-event="getrole"><i class="layui-icon layui-icon-link"></i> 配置角色</button>
	<button class="layui-btn layui-btn-sm" lay-event="getfinger"><i class="fa fa-hand-paper-o" aria-hidden="true"></i> 指纹采集</button>
	<button class="layui-btn layui-btn-sm" lay-event="repeat"><i class="layui-icon layui-icon-transfer"></i> 重置密码</button>
    <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="lock"><i class="layui-icon layui-icon-password"></i> 锁定</button>
    <button class="layui-btn layui-btn-sm" lay-event="unlock"><i class="layui-icon layui-icon-password"></i> 解锁</button>
	<input type="text" id="orgsearch" placeholder="机构名称查询" style="width:150px;font-size: 12px;margin-left:10px" class="ckinput">
	<input type="text" id="usersearch" placeholder="用户名查询" style="width:150px;font-size: 12px;margin-left:5px" class="ckinput">
	<button type="button" id="btn_search" style="margin-left:5px" class="layui-btn layui-btn-primary layui-btn-sm" lay-event="search"><i class="fa fa-search" aria-hidden="true"></i>查询</button>
  </div>
  </script>
</div>

<script id="useradd" type="text/html">
	<form class="layui-form" action="" id="useradd" style="margin-top:20px;width:360px">
		<div class="layui-form-item">
		    <label class="layui-form-label">用户名</label>
		    <div class="layui-input-block">
		      <input type="text" id="f_username" name="username" lay-verify="required" lay-reqtext="用户名是必填项，岂能为空？" placeholder="请输入" autocomplete="off" class="layui-input">
		    </div>
		  </div>
		  <div class="layui-form-item">
	    	<label class="layui-form-label">手机号</label>
		    <div class="layui-input-block">
		      <input type="tel" id="f_phone" name="phone" lay-verify="phone" autocomplete="off" class="layui-input">
		    </div>
	  	</div>
	  	<div class="layui-form-item">
	    	<label class="layui-form-label">所属机构</label>
		    <div class="layui-input-block">
		      <input type="button" id="f_orgname" name="orgname" onclick="dialog_orgselect()" class="layui-input" style="text-align: left;">
		    </div>
	  	</div>
	  	<div class="layui-form-item">
	    	<label class="layui-form-label">身份证号</label>
		    <div class="layui-input-block">
		      <input type="text" id="f_idcard" name="idcard" lay-verify="identity" autocomplete="off" class="layui-input">
		    </div>
	  	</div>
	  	<div class="layui-form-item">
	    	<label class="layui-form-label">岗位</label>
		    <div class="layui-input-block">
		      <input type="text" id="f_jobname" name="jobname" autocomplete="off" class="layui-input">
		    </div>
	  	</div>
	  	<div class="layui-form-item">
	    	<label class="layui-form-label">姓名</label>
		    <div class="layui-input-block">
		      <input type="text" id="f_realname" name="realname" autocomplete="off" class="layui-input">
		    </div>
	  	</div>
	  	 <div class="layui-form-item">
		    <label class="layui-form-label">性别</label>
		    <div class="layui-input-block">
		      <input id="sex_male" type="radio" name="sex" value="男" title="男" checked="">
		      <input id="sex_female" type="radio" name="sex" value="女" title="女">
		    </div>
		  </div>
		  <div class="layui-form-item layui-form-text">
		    <label class="layui-form-label">备注</label>
		    <div class="layui-input-block">
		      <textarea id="f_descriptor" name="descriptor" placeholder="请输入内容" class="layui-textarea"></textarea>
		    </div>
		  </div>
		  <input id="org_id" type="text" name="org_id" style="display:none"></input>
	</form>
</script>

<script type="text/javascript">
var table = layui.table;
var laypage = layui.laypage;
var form = layui.form;

var curopt = "";
var _currpage = 1;
var _pageSize = 20;
var _sorgname = "";
var _susername = "";
var _sroleid = ""; //配置角色用
layui.use([], function(){
	getData(_currpage,_pageSize,"","","");
	//getRolelist();
});

$('#ckpassword').on('keydown', function (event) {
    if (event.keyCode == 13) {
    	userckopt();
    	$("#dlgck").css('display','none');
		layer.closeAll();
    }
});


/*function getRolelist(){
	$.ajax({
		contentType: "application/json;charset=UTF-8",
		url : "getRoles.do?",
		type : "get",
		dataType : "json",
		success : function(msg) {
			table.render({
			    elem: '#rolelist'
			    ,data:msg
			    ,cols: [[
			      {type:'radio',fixed:true}
			      ,{field:'rolename', width:240, title: '角色名'}
			    ]]
			    ,page: false
			  });
			
		},
	    error : function(e){
	    	//dispalyEasyUILoad();
	    	if(e.status == 200){
        		parent.location.href = "login";
        	}else{
        		alert(e.status);
                alert(e.responseText);
        	}
	    }
	});
}*/
		 
function dialog_orgselect(){
	layer.open({
		  type: 2 //0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层） 
		  ,title: "选择机构" //标题
		  ,skin:"layui-layer-lan"   //layui-layer-lan:蓝色，layui-layer-molv：墨绿色，默认灰色
		  ,area: ['350px', '400px'] //宽度、高度
		  ,shade: 0.3
		  ,offset: 'auto'
		  ,anim:5 //弹出动画
		  ,shadeClose: false //弹框出现后，允许点击其它地方关闭
		  ,content: 'getorgtree.html'     //内容
		  ,btn: ['取消']
		  ,success:function (layero,index) {
			  	debugger;
	        	var iframe = window['layui-layer-iframe' + index];              
	        	iframe.child("usermanager_org","porg");
		  }	  
		  ,yes: function(index, layero){
		    //按钮【按钮一】的回调
			 	 //$("#orgtree").css('display','none'); 
			 	layer.close(index);
		  }
		  ,cancel: function(index,layero){ 
			    //右上角关闭回调
			    //$("#orgtree").css('display','none'); 
		 }
       });
}

function dialog_add(){
	var win = layer.open({
		  type: 1 //0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层） 
		  ,title: "添加用户" //标题
		  ,skin:"layui-layer-lan"   //layui-layer-lan:蓝色，layui-layer-molv：墨绿色，默认灰色
		  ,area: ['400px', '620px'] //宽度、高度
		  ,shade: 0.3
		  ,offset: 'auto'
		  ,anim:5 //弹出动画
		  ,shadeClose: false //弹框出现后，允许点击其它地方关闭
		  ,content: $("#useradd").html()     //内容
		  ,btn: ['确定', '取消'] //只是为了演示
		  ,success:function(layero){
			     var mask = $(".layui-layer-shade");
			     mask.appendTo(layero.parent());
			     //其中：layero是弹层的DOM对象
			     $('#f_username').removeAttr("disabled");
			     form.render();
			}
		,yes: function(index, layero){
		    //按钮【按钮一】的回调
		    	//debugger;
		    	if(submitForm('','')){
		    		//$("#useradd").css('display','none');
				 	//layer.close(index);
		    	}
			 	 
		  }
		  ,btn2: function(index, layero){
		    //按钮【按钮二】的回调
		    
		    	//$("#useradd").css('display','none'); 
		    	
		  }
		  ,cancel: function(){ 
			    //右上角关闭回调
			    //$("#useradd").css('display','none'); 
			    
		 }
	});
}

function ckdialgo_auth(){
	layer.open({
		  type: 1 //0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层） 
		  ,title: "复核" //标题
		  ,skin:"layui-layer-lan"   //layui-layer-lan:蓝色，layui-layer-molv：墨绿色，默认灰色
		  ,area: ['350px', '260px'] //宽度、高度
		  ,shade: 0.3
		  ,offset: 'auto'
		  ,anim:5 //弹出动画
		  ,shadeClose: false //弹框出现后，允许点击其它地方关闭
		  ,content: $("#dlgck")     //内容
		  ,btn: ['确定', '取消'] //只是为了演示
		  ,success:function(layero){
			     //var mask = $(".layui-layer-shade");
			     //mask.appendTo(layero.parent());
			     $('#ckname').focus();
			     //其中：layero是弹层的DOM对象
			}
		 ,yes: function(index, layero){
		    //按钮【按钮一】的回调
		    	userckopt();
	    		$("#dlgck").css('display','none');
			 	layer.close(index);
		    	
			 	 
		  }
		  ,btn2: function(index, layero){
		    	//按钮【按钮二】的回调
		    
		    	$("#dlgck").css('display','none'); 
		    	
		  }
		  ,cancel: function(){ 
			    //右上角关闭回调
			    $("#dlgck").css('display','none'); 
			    
		 }
	});
}

function submitForm(ckname,ckpassword){
	if($('#f_username').val().replace(/\s+/g,"").length < 2 || $('#f_username').val().replace(/\s+/g,"").length > 8){
		layer.msg("用户名长度为2~8位!");
		return false;
	}
	if($('#f_username').val().indexOf(",") >=0){
		layer.msg("用户名不能包含特殊字符','!");
		return false;
	}
	if(($('#f_idcard').val().replace(/\s+/g,"").length > 0) && (/^\d{15}(\d{2}[A-Za-z0-9])?$/i.test($('#f_idcard').val()) == false)){
		layer.msg("请输入正确的身份证号!");
		return false;
	}
	if(($('#f_phone').val().replace(/\s+/g,"").length > 0) && (/^(13|15|18)\d{9}$/i.test($('#f_phone').val()) == false) && (/^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/i.test($('#f_phone').val()) == false) ){
		layer.msg("请输入正确的电话号码!");
		return false;
	}
	if($('#org_id').val().replace(/\s+/g,"").length < 2){
		layer.msg("请选择所属机构!");
		return false;
	}
	if($('#f_realname').val().replace(/\s+/g,"").length < 2){
		layer.msg("请填写姓名!");
		return false;
	}
	if($('#f_realname').val().indexOf(",") >=0){
		layer.msg("姓名不能包含特殊字符','!");
		return false;
	}
	//debugger;
	var datastring = '{"username":"'+$('#f_username').val().replace(/\s+/g,"")+'","phone":"' + $('#f_phone').val().replace(/\s+/g,"") +'","org_name":"' + $('#f_orgname').val()
	+'","org_id":"' + $('#org_id').val() +'","jobname":"' + $('#f_jobname').val() +'","realname":"' + $('#f_realname').val().replace(/\s+/g,"") +'","idcard":"' + $('#f_idcard').val()
	+'","sex":"' + $("input[name='sex']:checked").val() +'","descriptor":"' + $('#f_descriptor').val()+ '","rname":"系统管理/用户管理/新增","ckname":"'+ckname+'","ckpassword":"'+ckpassword+'"}';

	$.ajax({
		type:"post",
		contentType: "application/json;charset=UTF-8",
		url: "useradd.do?",
		async:false,
		data:datastring,
     	dataType:"json",
        success: function(msg) {    //数据提交成功时返回数据
        	//debugger;
        	if(msg.status == "1"){
        		//clearForm();
        		getData(_currpage,_pageSize,_sorgname,_susername);
        		layer.closeAll();
        		//$("#useradd").css('display','none');
        	}else if(msg.status == "1211"){

        		$('#ckname').val('');
				$('#ckpassword').val('');
				ckdialgo_auth();
        		
        	}else{
        		layer.msg(msg.desc);
        	}						
        },
        error : function(e){
        	if(e.status == 200){
        		parent.location.href = "login";
        	}else{
        		alert(e.status);
                alert(e.responseText);
        	}
        }

	});		
}

function u_repeat(ckname,ckpassword){
	var userdata = table.checkStatus('tbl_user');
	var row = userdata.data[0];
	if (row){
		var datastring = '{"username":"'+row.username+'","userid":"' + row.id + '","rname":"系统管理/用户管理/重置密码","ckname":"'+ckname+'","ckpassword":"'+ckpassword+'"}';
		if(ckname == ''){
			layer.confirm('确定要重置该用户?', {
				  btn: [ '确定', '取消'] //可以无限个按钮				  
				}, function(index, layero){
				  //按钮【按钮一】的回调
					$.ajax({
						type:"post",
						contentType: "application/json;charset=UTF-8",
						url: "user_reset.do?",
						async:false,
						data:datastring,
				     	dataType:"json",
				        success: function(msg) {    //数据提交成功时返回数据
							if(msg.status == "1"){
								layer.closeAll();
								//getData(_currpage,_pageSize);									
							}else if(msg.status == "1211"){
								$('#ckname').val('');
								$('#ckpassword').val('');
								//debugger;
								ckdialgo_auth();
				        		
							}
				        	layer.msg(msg.desc);						
							
				        },
				        error : function(e){
				        	if(e.status == 200){
				        		parent.location.href = "login";
				        	}else{
				        		alert(e.status);
				                alert(e.responseText);
				        	}
				        }
	
					});
				}, function(index){					
					layer.closeAll();
				});			
			}else{
				
				$.ajax({
					type:"post",
					contentType: "application/json;charset=UTF-8",
					url: "user_reset.do?",
					async:false,
					data:datastring,
			     	dataType:"json",
			        success: function(msg) {    //数据提交成功时返回数据
						if(msg.status == "1"){
							layer.closeAll();
						}else if(msg.status == "1211"){
							$('#ckname').val('');
							$('#ckpassword').val('');
							ckdialgo_auth();
						}
						layer.msg(msg.desc);						
						
			        },
			        error : function(e){
			        	if(e.status == 200){
			        		parent.location.href = "login";
			        	}else{
			        		alert(e.status);
			                alert(e.responseText);
			        	}
			        }
		
				});
			}
							
		}else{
			layer.msg('需选择用户!');
		}
}

function u_lock(ckname,ckpassword){
	var userdata = table.checkStatus('tbl_user');
	var row = userdata.data[0];
	if(row.status == 1){
		layer.msg('用户状态已锁定!');
		return;
	}else{
		
		var datastring = '{"userid":"'+row.id + '","username":"' + row.username + '","rname":"系统管理/用户管理/状态变更","ckname":"'+ckname+'","ckpassword":"'+ckpassword+'"}';
		if (row){
			$.ajax({
				type:"post",
				contentType: "application/json;charset=UTF-8",
				url: "user_lock.do?",
				async:false,
				data:datastring,
		     	dataType:"json",
		        success: function(msg) {    //数据提交成功时返回数据
					if(msg.status == "1"){
						layer.closeAll();
						getData(_currpage,_pageSize,_sorgname,_susername);	
					}else if(msg.status == "1211"){
						$('#ckname').val('');
						$('#ckpassword').val('');
						ckdialgo_auth();
					}else{
						layer.msg(msg.desc);	
					}
										
					
		        },
		        error : function(e){
		        	if(e.status == 200){
		        		parent.location.href = "login";
		        	}else{
		        		alert(e.status);
		                alert(e.responseText);
		        	}
		        }

			});
								
		}else{
			layer.msg('需选择用户!');
		}
	}
	
}

function u_unlock(ckname,ckpassword){
	var userdata = table.checkStatus('tbl_user');
	var row = userdata.data[0];
	if(row.status != 1){
		layer.msg('用户状态正常!');
		return;
	}else{
		
		var datastring = '{"userid":"' + row.id + '","username":"' + row.username + '","rname":"系统管理/用户管理/状态变更","ckname":"'+ckname+'","ckpassword":"'+ckpassword+'"}';
		if (row){
			$.ajax({
				type:"post",
				contentType: "application/json;charset=UTF-8",
				url: "user_unlock.do?",
				async:false,
				data:datastring,
		     	dataType:"json",
		        success: function(msg) {    //数据提交成功时返回数据
					if(msg.status == "1"){
						layer.closeAll();
						getData(_currpage,_pageSize,_sorgname,_susername);
					}else if(msg.status == "1211"){
						$('#ckname').val('');
						$('#ckpassword').val('');
						ckdialgo_auth();
					}else{
						layer.msg(msg.desc);	
					}										
					
		        },
		        error : function(e){
		        	if(e.status == 200){
		        		parent.location.href = "login";
		        	}else{
		        		alert(e.status);
		                alert(e.responseText);
		        	}
		        }

			});
								
		}else{
			layer.msg('需选择用户!');
		}
	}
	
}


table.on('toolbar(tbl_user)', function(obj){
	//debugger;
	var checkStatus = table.checkStatus(obj.config.id);
    switch(obj.event){
      case 'add':
    	  curopt = 'add';
    	  dialog_add();
      break;
      case 'del':
    	//debugger;
    	curopt = "del";
    	if(checkStatus.data.length == 0){
    		layer.msg('请先选择用户!');
    		return;
    	}
        u_remove('','');
      break;
      case 'edit':
    	  if(checkStatus.data.length == 0){
      		layer.msg('请先选择用户!');
      		return;
      	  }
    	  curopt = 'edit';
    	  dialog_edit('','',checkStatus.data[0]);
      break;
      case 'getrole':
    	  if(checkStatus.data.length == 0){
      		layer.msg('请先选择用户!');
      		return;
      	  }
    	  curopt = 'config';
    	  dialog_role(checkStatus.data[0]);
      break;
      case 'getfinger':
    	  if(checkStatus.data.length == 0){
      		layer.msg('请先选择用户!');
      		return;
      	  }
    	  curopt = 'finger';
    	  dialog_finger(checkStatus.data[0]);
      break;
      case 'repeat':
    	  if(checkStatus.data.length == 0){
      		layer.msg('请先选择用户!');
      		return;
      	  }
    	  curopt = 'repeat';
    	  u_repeat('','');
        break;
      case 'lock':
    	  if(checkStatus.data.length == 0){
      		layer.msg('请先选择用户!');
      		return;
      	  }
    	  curopt = 'lock';
    	  u_lock('','');
        break;
      case 'unlock':
    	  if(checkStatus.data.length == 0){
      		layer.msg('请先选择用户!');
      		return;
      	  }
    	  curopt = 'unlock';
    	  u_unlock('','');
        break;
      case 'search':
      	  curopt = "search";    
      	  _currpage = 1;
      	  getData(_currpage,_pageSize,$('#orgsearch').val().replace(/\s+/g,""),$('#usersearch').val().replace(/\s+/g,""));           	
          break;
    };
    
  });

function getData(pageNumber,pageSize,sorgname,susername){
	_sorgname = sorgname;
	_susername = susername;
	//var page_size = table_name.config.limit;
	var datastring = '{"pageNumber":'+pageNumber+',"pageSize":'+ pageSize + ',"orgname":"' + _sorgname + '","username":"' + _susername + '"}';
	var layeri = layer.load(2);
	$.ajax({
		contentType: "application/json;charset=UTF-8",
		url : "getUserlist",
		type : "post",
		data : datastring,
		dataType : "json",
		success : function(msg) {
			debugger;
			tablerender(msg);
			page(msg);
			layer.close(layeri);
		},
        error : function(e){
        	layer.close(layeri);
        	if(e.status == 200){
        		parent.location.href = "login";
        	}else{
        		alert(e.status);
                alert(e.responseText);
        	}
        }
	});
}

function tablerender(data){	
	table.render({
		  elem: '#tbl_user'
		  ,toolbar: '#toolbarDemo'
		  ,cellMinWidth: 50
		  ,cols: [
			  [
			  {type:'radio', hide: true}
		    ,{field:'username', title: '用户名'} 
		    ,{field:'realname', title: '姓名', width:140}	
		    ,{field:'org_name', title: '所属机构'}
		    ,{field:'phone', title: '手机号', width:120}
		    ,{field:'idcard', title: '身份证号', width:120}
		    ,{field:'jobname', title: '岗位'}	
		    ,{field:'sex', title: '性别', align: 'center', width:80}
		    ,{field:'rolename', title: '角色', align: 'center'}
		    ,{field:'status', title: '状态', width:100, align: 'center', templet: '#statusTpl'}
		    ,{field:'authtype', title: '验证方式', width:100, align: 'center', templet: '#authTpl'}
		    ,{field:'descriptor', title: '备注'}
		  ]
			  ]
		  ,data:data.datalist
		  ,limit: data.pageSize
		  ,height: parent.iframeH - 60,
		  done: function(res, curr, count){
			  $('#orgsearch').val(_sorgname);
			  $('#usersearch').val(_susername);
		  }
		});	
	
	table.on('row(tbl_user)', function(obj){
	    var data = obj.data;    
	    obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
		//选中radio样式
		obj.tr.find('i[class="layui-anim layui-icon"]').trigger("click");
	});
}

function numpage(pageNumber, pageSize) {
	var datastring = '{"pageNumber":'+pageNumber+',"pageSize":'+ pageSize + ',"orgname":"' + _sorgname + '","username":"' + _susername + '"}';
	var layeri = layer.load(2);
	//debugger;
	$.ajax({
		contentType: "application/json;charset=UTF-8",
		url : "getUserlist.do?",
		type : "post",
		data : datastring,
		dataType : "json",
		success : function(msg) {
			//debugger;
			layer.close(layeri);
			tablerender(msg);
		},
        error : function(e){
        	layer.close(layeri);
        	if(e.status == 200){
        		parent.location.href = "login";
        	}else{
        		alert(e.status);
                alert(e.responseText);
        	}
        }
	});
}

function page(data) {
    laypage.render({
        elem: 'page', //注意，这里的 page 是 ID，不用加 # 号
        count: data.totalCount, //数据总数，从服务端得到
        limit: data.pageSize,  // 每页条数
        limits: [10, 20, 30, 40, 50],
        layout: ['count', 'prev', 'page', 'next', 'limit', 'skip'],
        curr: _currpage,
        jump: function (obj, first) {
            //console.log(obj)
            //obj包含了当前分页的所有参数，比如：
            //layer.msg(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
            //console.log(obj.limit); //得到每页显示的条数

            //首次不执行
            if (!first) {
                //do something
                _currpage = obj.curr;
                _pageSize = obj.limit;
                numpage(obj.curr, obj.limit)  // 分页点击传参 
            }
        }
    });
    form.render(); 
}

function dialog_role(data){
	//debugger;	
	var win = layer.open({
		  type: 2 //0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层） 
		  ,title: "角色选择" //标题
		  ,skin:"layui-layer-lan"   //layui-layer-lan:蓝色，layui-layer-molv：墨绿色，默认灰色
		  ,area: ['350px', '500px'] //宽度、高度
		  ,shade: 0.3
		  ,offset: 'auto'
		  ,anim:5 //弹出动画
		  ,shadeClose: false //弹框出现后，允许点击其它地方关闭
		  ,content: "template_rolelist_single.html"     //内容
		  ,btn: ['提交', '取消'] //只是为了演示
		  ,success:function(layero,index){
			    var iframe = window['layui-layer-iframe' + index];
                iframe.child(data.rolename);
			}
		  ,yes: function(index, layero){
		    //按钮【按钮一】的回调	
		    	iframeWin = window[layero.find('iframe')[0]['name']];
		    	var srole = iframeWin.getCheckedUsers();	
		    	debugger;
		    	_sroleid = srole[0].id;
		    	u_config('','', _sroleid);
		    	//$("#tb_rolelist").css('display','none');
				layer.close(index);	    	
			 	 
		  }
		  ,btn2: function(index, layero){
		    //按钮【按钮二】的回调
		    
		    	//$("#tb_rolelist").css('display','none'); 
		    	
		  }
		  ,cancel: function(){ 
			    //右上角关闭回调
			    //$("#tb_rolelist").css('display','none'); 
			    
		 }
	});
}

function dialog_finger(data){
	//debugger;	
	var win = layer.open({
		  type: 2 //0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层） 
		  ,title: "指纹采集" //标题
		  ,skin:"layui-layer-lan"   //layui-layer-lan:蓝色，layui-layer-molv：墨绿色，默认灰色
		  ,area: ['532px', '500px'] //宽度、高度
		  ,shade: 0.3
		  ,offset: 'auto'
		  ,anim:5 //弹出动画
		  ,shadeClose: false //弹框出现后，允许点击其它地方关闭
		  ,content: "template_finger.html"     //内容
		  ,btn: ['关闭'] //只是为了演示
		  ,success:function(layero,index){
			    var iframe = window['layui-layer-iframe' + index];
                iframe.child(data.username);
			}
		  ,yes: function(index, layero){
				layer.close(index);	    	
			 	 
		  }
		  ,cancel: function(){ 
			    //右上角关闭回调
			    //$("#tb_rolelist").css('display','none'); 
			    
		 }
	});
}

function u_config(ckname,ckpassword,roleid){
	var checkStatus = table.checkStatus('rolelist');
	var userdata = table.checkStatus('tbl_user');
	//debugger;
	var datastring = '{"userid":"'+userdata.data[0].id+'","username":"' +  userdata.data[0].username+'","roleid":"' +  roleid + '","rname":"系统管理/用户管理/设置角色权限","ckname":"'+ckname+'","ckpassword":"'+ckpassword+'"}';
	$.ajax({
		type:"post",
		contentType: "application/json;charset=UTF-8",
		url: "userupdaterole.do?",
		async:false,
		data:datastring,
     	dataType:"json",
        success: function(msg) {    //数据提交成功时返回数据
        	if(msg.status == "1"){        		
        		getData(_currpage,_pageSize,_sorgname,_susername);
        		layer.closeAll();

        	}else if(msg.status == "1211"){
        		$('#ckname').val('');
				$('#ckpassword').val('');
				ckdialgo_auth();
        	}else{
        		layer.msg(msg.desc);
        	}						
        },
        error : function(e){
        	if(e.status == 200){
        		parent.location.href = "login";
        	}else{
        		alert(e.status);
                alert(e.responseText);
        	}
        }

	});	
}

function dialog_edit(ckname,ckpassword,data){
	//debugger;
	
	var win = layer.open({
		  type: 1 //0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层） 
		  ,title: "编辑用户" //标题
		  ,skin:""   //layui-layer-lan:蓝色，layui-layer-molv：墨绿色，默认灰色
		  ,area: ['400px', '620px'] //宽度、高度
		  ,shade: 0.3
		  ,offset: 'auto'
		  ,anim:5 //弹出动画
		  ,shadeClose: false //弹框出现后，允许点击其它地方关闭
		  ,content: $("#useradd").html()     //内容
		  ,btn: ['确定', '取消'] //只是为了演示
		  ,success:function(layero){
			     var mask = $(".layui-layer-shade");
			     mask.appendTo(layero.parent());
			     //其中：layero是弹层的DOM对象
			     $("#f_username").val(data.username);
			 	 $("#f_phone").val(data.phone);
			 	 $("#f_orgname").val(data.org_name);
			 	 $("#f_jobname").val(data.jobname);
			 	 $("#f_realname").val(data.realname);
			 	 $("#f_idcard").val(data.idcard);
			 	 $("#f_descriptor").val(data.descriptor);
			 	 $("#org_id").val(data.org_id);
			   	 if(data.sex == '男'){
			 		//$("#sex_female").removeAttr("checked");
			 		//$("#sex_male").attr("checked","checked");	
			 		$("input[name=sex][value=女]").prop("checked","false");
			 	    $("input[name=sex][value=男]").prop("checked","true");
			 	 }else{
			 		//$("#sex_male").removeAttr("checked");
			 		//$("#sex_female").attr("checked","checked");
			 		$("input[name=sex][value=男]").prop("checked","false");
			 	    $("input[name=sex][value=女]").prop("checked","true");
			 		
			 	 }
			 	
			     $('#f_username').attr("disabled","disabled");
			     form.render(); 
			}
		,yes: function(index, layero){
		    //按钮【按钮一】的回调		    	
		    	if(u_edit('','')){
		    		//$("#useradd").css('display','none');
				 	//layer.close(index);
		    	}
			 	 
		  }
		  ,btn2: function(index, layero){
		    //按钮【按钮二】的回调
		    
		    	//$("#useradd").css('display','none'); 
		    	
		  }
		  ,cancel: function(){ 
			    //右上角关闭回调
			    //$("#useradd").css('display','none'); 
			    
		 }
	});
}

function u_edit(ckname,ckpassword){

	if(($('#f_idcard').val().replace(/\s+/g,"").length > 0) && (/^\d{15}(\d{2}[A-Za-z0-9])?$/i.test($('#f_idcard').val()) == false)){
		layer.msg("请输入正确的身份证号!");
		return false;
	}
	if(($('#f_phone').val().replace(/\s+/g,"").length > 0) && (/^(13|15|18)\d{9}$/i.test($('#f_phone').val()) == false) && (/^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/i.test($('#f_phone').val()) == false) ){
		layer.msg("请输入正确的电话号码!");
		return false;
	}
	if($('#org_id').val().replace(/\s+/g,"").length < 2){
		layer.msg("请选择所属机构!");
		return false;
	}
	if($('#f_realname').val().replace(/\s+/g,"").length < 2){
		layer.msg("请填写姓名!");
		return false;
	}
	if($('#f_realname').val().indexOf(",") >=0){
		layer.msg("用户名不能包含特殊字符','和空格!");
		return false;
	}
	var userdata = table.checkStatus('tbl_user');
	var row = userdata.data[0];
	//debugger;
	var datastring = '{"username":"'+$('#f_username').val().replace(/\s+/g,"")+'","phone":"' + $('#f_phone').val().replace(/\s+/g,"") +'","org_name":"' + $('#f_orgname').val() + '","userid":"' + row.id
	+'","org_id":"' + $('#org_id').val() +'","jobname":"' + $('#f_jobname').val() +'","realname":"' + $('#f_realname').val().replace(/\s+/g,"") +'","idcard":"' + $('#f_idcard').val()
	+'","sex":"' + $("input[name='sex']:checked").val() +'","descriptor":"' + $('#f_descriptor').val()+ '","rname":"系统管理/用户管理/修改","ckname":"'+ckname+'","ckpassword":"'+ckpassword+'"}';

	$.ajax({
		type:"post",
		contentType: "application/json;charset=UTF-8",
		url: "useredit.do?",
		async:false,
		data:datastring,
     	dataType:"json",
        success: function(msg) {    //数据提交成功时返回数据
        	if(msg.status == "1"){        		
        		getData(_currpage,_pageSize,_sorgname,_susername);
        		layer.closeAll();
        		$("#useradd").css('display','none');
        		//clearForm();
        	}else if(msg.status == "1211"){
        		$('#ckname').val('');
				$('#ckpassword').val('');
				ckdialgo_auth();
        	}else{
        		layer.msg(msg.desc);
        	}						
        },
        error : function(e){
        	if(e.status == 200){
        		parent.location.href = "login";
        	}else{
        		alert(e.status);
                alert(e.responseText);
        	}
        }

	});	
}
  
function u_remove(ckname,ckpassword){	
	var userdata = table.checkStatus('tbl_user');
	var row = userdata.data[0];
	if (row){
		
		var datastring = '{"username":"'+row.username + '","userid":"' + row.id + '","checkname":"","rname":"系统管理/用户管理/删除","id":"' + row.id +'","ckname":"'+ckname+'","ckpassword":"'+ckpassword+'"}';
		if(ckname == ''){
			layer.confirm('确定要删除该用户?', {
				  btn: ['确定', '取消'] //可以无限个按钮				  
				}, function(index, layero){
				  //按钮【按钮一】的回调
				  	$.ajax({
						type:"post",
						contentType: "application/json;charset=UTF-8",
						url: "userdel.do?",
						async:false,
						data:datastring,
				     	dataType:"json",
				        success: function(msg) {    //数据提交成功时返回数据
							if(msg.status == "1"){
								layer.closeAll();
								getData(_currpage,_pageSize,_sorgname,_susername);									
							}else if(msg.status == "1211"){
								$('#ckname').val('');
								$('#ckpassword').val('');
								//debugger;
								ckdialgo_auth();
				        		
							}else{
								layer.msg(msg.desc);
							}						
							
				        },
				        error : function(e){
				        	if(e.status == 200){
				        		parent.location.href = "login";
				        	}else{
				        		alert(e.status);
				                alert(e.responseText);
				        	}
				        }

					});	
					
				}, function(index){
					layer.closeAll();
				});			
		}else{
			
			$.ajax({
				type:"post",
				contentType: "application/json;charset=UTF-8",
				url: "userdel.do?",
				async:false,
				data:datastring,
		     	dataType:"json",
		        success: function(msg) {    //数据提交成功时返回数据
					if(msg.status == "1"){
						getData(_currpage,_pageSize,_sorgname,_susername);
					}else if(msg.status == "1211"){
						$('#ckname').val('');
						$('#ckpassword').val('');
						ckdialgo_auth();
					}else{
						layer.msg(msg.desc);
					}						
					
		        },
		        error : function(e){
		        	if(e.status == 200){
		        		parent.location.href = "login";
		        	}else{
		        		alert(e.status);
		                alert(e.responseText);
		        	}
		        }

			});
		}
							
	}else{
		layer.msg('需选择用户!');
	}							
}

function userckopt(){
	//debugger;
	var ckname = $('#ckname').val();
	if(ckname == ''){
		layer.msg('请填写用户账号!');
		return;
	}
	var ckpassword = $('#ckpassword').val();
	if(curopt == "add"){
		submitForm(ckname,$.base64.encode(ckpassword));
	}else if(curopt == "edit"){
		u_edit(ckname,$.base64.encode(ckpassword));
	}else if(curopt == "del"){
		u_remove(ckname,$.base64.encode(ckpassword));
	}else if(curopt == "config"){
		u_config(ckname,$.base64.encode(ckpassword),_sroleid);
	}else if(curopt == "repeat"){
		u_repeat(ckname,$.base64.encode(ckpassword));
	}else if(curopt == "lock"){
		u_lock(ckname,$.base64.encode(ckpassword));
	}else if(curopt == "unlock"){
		u_unlock(ckname,$.base64.encode(ckpassword));
	}
	
	
}

function userckopt_cancel(){
	$('#ckname').val('');
	$('#ckpassword').val('');	
}
</script>
<script type="text/html" id="statusTpl">
  {{#  if(d.status == '0'){ }}	
    <span>正常</span>
  {{#  } else if(d.status == '1') { }}
    <span style="color: #F581B1;">锁定</span>
  {{#  } else if(d.status == '2') { }}
	<span style="color: #F581B1;">未激活</span>
  {{#  } }}
</script>
<script type="text/html" id="authTpl">
  {{#  if(d.authtype == '0'){ }}
    <span>系统设置</span>
  {{#  } else if(d.authtype == '1') { }}
    <span>用户密码</span>
  {{#  } else if(d.authtype == '2') { }}
	<span>指纹验证</span>
  {{#  } }}
</script>
</body>
</html>
